package com.mycoffee.ui;

import com.example.mycoffee.MainActivity;
import com.example.mycoffee.R;
import android.app.Activity;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainButto extends ActivityGroup{

	private ViewPager tabpager;
	private ImageView img_sh;
	private ImageView img_me;
	private ImageView img_mes;
	private ImageView img_owner,img_cul;
	private int flag=0;
	private LinearLayout bodyView;
	private String sessionid;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setFullScreen(false);
		setContentView(R.layout.buttobut);
		
		initView();
		showView(flag);
		setonClik(flag);
	}
    private void initView()
     {
    	bodyView = (LinearLayout) findViewById(R.id.body);
    	img_me=(ImageView) findViewById(R.id.img_me);
		img_mes=(ImageView) findViewById(R.id.img_mes);
		img_sh=(ImageView) findViewById(R.id.img_sh);
		img_owner=(ImageView) findViewById(R.id.img_owner);
		img_cul=(ImageView) findViewById(R.id.img_cul);
		tabpager=(ViewPager) findViewById(R.id.tabpager);
	}
	public int setonClik(int i) {
    	img_sh.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				flag=0;
				showView(flag);
			}
		});
    	img_me.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				flag=1;
				showView(flag);
			}
		});
    	img_mes.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
					flag=2;
					showView(flag);	
			}
		});
		
    	img_cul.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				flag=3;
				showView(flag);	
			}
    	});
    	img_owner.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				flag=4;
				showView(flag);	
			}
			
//			@Override 
//			public void onClick(View arg0) {
//				username =App.getContext().getUserName();
//				encodePassWord=App.getContext().getEncodePassWord();
//				System.out.println("encodePassWord"+encodePassWord+"username"+username);
//				Thread();
//				if (encodePassWord!=null||username!=null) {
//					flag=5;
//					showView(flag);
//					
//				}else {
//					flag=4;
//					showView(flag);
//				}
//				
//			}
		});
		return i;

	}

//    @SuppressWarnings("deprecation")
	public void showView(int flag){
		switch (flag) {
		case 0:
			//shouye
			bodyView.removeAllViews();
			Intent homedimen=new Intent(MainButto.this, MainActivity.class);
			homedimen.putExtra("sessionId", getIntent().getStringExtra("sessionid"));
			View v = getLocalActivityManager().startActivity("home_a",homedimen).getDecorView();
			img_sh.setBackgroundResource(R.drawable.icon3);
			img_me.setBackgroundResource(R.drawable.icon1);
			img_mes.setBackgroundResource(R.drawable.icon1);
			img_cul.setBackgroundResource(R.drawable.icon1);
			img_owner.setBackgroundResource(R.drawable.icon1);
			bodyView.addView(v);
			break;
		case 1:
			//caidan
			bodyView.removeAllViews();
			Intent tradeintent = new Intent(MainButto.this,mycoffe.class);
			tradeintent.putExtra("sessionId", getIntent().getStringExtra("sessionid"));
			View tradeView = getLocalActivityManager().startActivity("tadre_a",tradeintent).getDecorView();
			bodyView.addView(tradeView);
			img_sh.setBackgroundResource(R.drawable.icon1);
			img_me.setBackgroundResource(R.drawable.icon3);
			img_mes.setBackgroundResource(R.drawable.icon1);
			img_cul.setBackgroundResource(R.drawable.icon1);
			img_owner.setBackgroundResource(R.drawable.icon1);
			break;
		case 2:
			//xiaoxi
			bodyView.removeAllViews();
			bodyView.addView(getLocalActivityManager().startActivity("info_b", 
					new Intent(MainButto.this,Mymessage.class)).getDecorView());
			img_sh.setBackgroundResource(R.drawable.icon1);
			img_me.setBackgroundResource(R.drawable.icon1);
			img_mes.setBackgroundResource(R.drawable.icon3);
			img_cul.setBackgroundResource(R.drawable.icon1);
			img_owner.setBackgroundResource(R.drawable.icon1);
			
			break;
		case 3:
			//wenhua
			bodyView.removeAllViews();
			bodyView.addView(getLocalActivityManager().startActivity("info_b", 
					new Intent(MainButto.this,Magazine.class)).getDecorView());
			img_sh.setBackgroundResource(R.drawable.icon1);
			img_me.setBackgroundResource(R.drawable.icon1);
			img_mes.setBackgroundResource(R.drawable.icon1);
			img_cul.setBackgroundResource(R.drawable.icon3);
			img_owner.setBackgroundResource(R.drawable.icon1);
			break;
		case 4:
			//wode
			
			bodyView.removeAllViews();
			bodyView.addView(getLocalActivityManager().startActivity("info_b", 
					new Intent(MainButto.this,Login.class)).getDecorView());
			img_sh.setBackgroundResource(R.drawable.icon1);
			img_me.setBackgroundResource(R.drawable.icon1);
			img_mes.setBackgroundResource(R.drawable.icon1);
			img_cul.setBackgroundResource(R.drawable.icon1);
			img_owner.setBackgroundResource(R.drawable.icon3);
			break;
//		case 4:
	
//			bodyView.removeAllViews();
//			Intent myIntent=new Intent(MainButto.this, Milk.class);
//			myIntent.putExtra("IDCard", getIntent().getStringExtra("IDCard"));
//			myIntent.putExtra("EncodePassWord", getIntent().getStringExtra("EncodePassWord"));
//			myIntent.putExtra("CustomRiskLevel", getIntent().getStringExtra("CustomRiskLevel"));
//			myIntent.putExtra("DepositacctName", getIntent().getStringExtra("DepositacctName"));
//			myIntent.putExtra("TotalFundMarketValue", getIntent().getStringExtra("TotalFundMarketValue"));
//			myIntent.putExtra("CountFund", getIntent().getStringExtra("CountFund"));
//			myIntent.putExtra("PassWord", getIntent().getStringExtra("PassWord"));
//			myIntent.putExtra("UserName", getIntent().getStringExtra("UserName"));
//			myIntent.putExtra("msg", getIntent().getStringExtra("msg"));
//			myIntent.putExtra("Mobile", getIntent().getStringExtra("Mobile"));
//			myIntent.putExtra("certificateno", getIntent().getStringExtra("certificateno"));
//			myIntent.putExtra("depositacct", getIntent().getStringExtra("depositacct"));
//			myIntent.putExtra("certificatetype", getIntent().getStringExtra("certificatetype"));
//			myIntent.putExtra("Moneyaccount", getIntent().getStringExtra("Moneyaccount"));
//			myIntent.putExtra("Custno", getIntent().getStringExtra("Custno"));
//			myIntent.putExtra("channelid", getIntent().getStringExtra("channelid"));
//			myIntent.putExtra("Fundcode", getIntent().getStringExtra("Fundcode"));
//			myIntent.putExtra("sessionid", sessionid);
			
//			View view = getLocalActivityManager().startActivity("my_a",myIntent).getDecorView();
//			bodyView.addView(view);
//			img_sh.setBackgroundResource(R.drawable.home_a);
//			img_me.setBackgroundResource(R.drawable.info_a);
//			img_mes.setBackgroundResource(R.drawable.trade_a);
//			img_owner.setBackgroundResource(R.drawable.my_b);
//			
//			break;

		}
		return;
	}
	
    public void setFullScreen(boolean fullScreen) {
		if (fullScreen) {
			requestWindowFeature(Window.FEATURE_NO_TITLE);
			getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
					WindowManager.LayoutParams.FLAG_FULLSCREEN);
		} else {
			requestWindowFeature(Window.FEATURE_NO_TITLE);
		}

	}
	
}
